package org.groupg.practice;

import org.mockserver.integration.ClientAndServer;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.mockserver.model.Parameter.param;

public class MockServerSetupExample {
    public static void main(String[] args) {
        // 在端口 1080 上启动 MockServer
        ClientAndServer mockServer = ClientAndServer.startClientAndServer(1080);

        // 设置期望：当收到带特定查询参数的 GET 请求时，返回特定响应
        mockServer
            .when(
                request()
                    .withMethod("GET")
                    .withPath("/test")
                    .withQueryStringParameters(
                        param("p", "1") // 匹配查询参数 p=1
                    )
            )
            .respond(
                response()
                    .withStatusCode(200)
                    .withBody("test1") // 返回响应体 "test1"
                    .withHeader("Content-Type", "text/plain")
            );

        // 设置另一个期望：匹配 p=2
        mockServer
            .when(
                request()
                    .withMethod("GET")
                    .withPath("/test")
                    .withQueryStringParameters(
                        param("p", "2")
                    )
            )
            .respond(
                response()
                    .withStatusCode(200)
                    .withBody("test2") // 返回响应体 "test2"
                    .withHeader("Content-Type", "text/plain")
            );

        System.out.println("MockServer is running on port 1080...");
        // 保持运行，以便测试
        // mockServer.stop(); // 测试完成后可停止
    }
}